package com.qf.servlet;

import com.qf.entity.Page;
import com.qf.service.StuService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 带分页的学生查询列表
 *
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@WebServlet(urlPatterns = "/stuquerypage")
public class StuQueryPageServlet extends HttpServlet {

    private StuService stuService = new StuService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //告知两个参数 - 当前要查询第几页 每页要显示多少条
        String page = req.getParameter("page");//当前页码
        String pageSize = req.getParameter("pageSize");//每页显示多少条

        //封装成实体类
        Page p = new Page()
                .setPage(Integer.parseInt(page))
                .setPageSize(Integer.parseInt(pageSize));

        //调用Service层进行分页
        p = stuService.queryStusPage(p);

        //响应给客户端的内容 - 当前要查询第几页 每页要显示多少条 共有多少页 共有多少条数据 当前页的数据列表
        req.setAttribute("page", p);
        //转发给学生列表页
        req.getRequestDispatcher("stulist.jsp").forward(req, resp);
    }
}
